package com.saa.strategy.controller;

import com.saa.application.po.SaaApplicationInfo;
import com.saa.application.service.ApplicationInfoService;
import com.saa.application.vo.SaaApplicationInfoVo;
import com.saa.common.vo.OmsResultVo;
import com.saa.strategy.service.SaaStrategyService;
import com.saa.strategy.vo.SaaStrategyPageVo;
import com.saa.strategy.vo.SaaStrategyVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/strategy")
public class SaaStrategyController {
    private Logger logger = LoggerFactory.getLogger(SaaStrategyController.class);

    @Autowired
    private SaaStrategyService saaStrategyService;

    @PostMapping("/queryStrategy")
    public OmsResultVo queryStrategy(@RequestBody SaaStrategyVo saaStrategyVo) {
        try {
            return saaStrategyService.queryStrategy(saaStrategyVo);
        } catch (Exception e) {
            return OmsResultVo.builder(500, "新增失败", null);
        }
    }

    @PostMapping("/queryStrategyDetail")
    public OmsResultVo queryStrategyDetail(@RequestBody SaaStrategyVo saaStrategyVo) {
        try {
//            System.out.println(applicationInfoService.getApplicationInfoPage(applicationInfo, applicationInfo.getPage(), applicationInfo.getPageSize()));
            return saaStrategyService.queryStrategyDetail(saaStrategyVo);
        } catch (Exception e) {
            e.printStackTrace();
            return OmsResultVo.builder(500, "查询失败", null);
        }
    }

    @PostMapping("/createStrategyDetail")
    public OmsResultVo createStrategyDetail(@RequestBody SaaStrategyPageVo saaStrategyVo) {
        try {
            return saaStrategyService.createStrategyDetail(saaStrategyVo);
        } catch (Exception e) {
            return OmsResultVo.builder(500, "查询失败", null);
        }
    }

    @PostMapping("/updateStrategyDetail")
    public OmsResultVo updateStrategyDetail(@RequestBody SaaStrategyPageVo saaStrategyVo) {
        try {
            return saaStrategyService.updateStrategyDetail(saaStrategyVo);
        } catch (Exception e) {
            return OmsResultVo.builder(500, "查询失败", null);
        }
    }
}
